  
  /*******************************
   ** Copyleft:			**
   ** Daskalakis Dimitris	**
   ** Parasxos   Alexandros	**
   ** Pierris	 Georgios	**
   ** Version 	 0.1		**
   *******************************/

  #include "analyzer.tab.h"
  #include <stdlib.h>


white [\n\t ]
letter [a-zA-Z]
numb [0-9]+


label {letter}({letter}|{numb}|"_")*

register "$"[rR](([1-2]?[0-9])|30|31) 


 int numline=1;

%%


add			{	return TK_add;		}  
sub			{ 	return TK_sub; 		} 
and			{ 	return TK_and; 		} 
not			{ 	return TK_not; 		} 
or			{ 	return TK_or;	 	} 
slt			{ 	return TK_slt; 		} 
jr			{	return TK_jr;	 	} 
jalr			{ 	return TK_jalr;		} 
jal			{ 	return TK_jal; 		}	 
j			{	return TK_j; 		} 
addi			{ 	return TK_addi; 	} 
subi			{ 	return TK_subi; 	} 
andi			{ 	return TK_andi; 	} 
ori			{ 	return TK_ori; 		} 
slti			{ 	return TK_slti; 	} 
lui			{ 	return TK_lui; 		}
beqz			{ 	return TK_beqz; 	} 
bneq			{ 	return TK_bneq; 	} 
lw			{ 	return TK_lw; 		} 
sw			{ 	return TK_sw; 		}

nop			{	return TK_nop;		}
mov			{	return TK_mov;		}



{register}		{	
				yylval.val = atoi( yytext+2 );
				return TK_reg; 
			}

{label}":"		{ 
				yylval.str = yytext;
				return TK_new_label; 
			}


{label}			{
				yylval.str = yytext;
				return TK_label; 
			}


"-"?{numb}			{ 
				yylval.val = atoi( yytext );
				return TK_immed_disp; 
			}

"//".*			{ ; }

[\t, ]			{ ; }

"\n"			{ numline++; }

.			{ printf("UNEXPECTED ERROR: %s in line %d\n",yytext,numline); }


%% 
/*
int main () {
                int token;
                while ((token=yylex())!=0) 
                        printf("Token found %d\n",token);
}
*/

